﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections;

namespace GetIP2PCName
{
    class ComputerAddressInfo
    {
        private int startIP = 0;
        private int endIP = 0;
        private string ipPrefix = "";
        private ArrayList computerList = null;

        public ComputerAddressInfo(string ipprefex, int startip, int endip)
        {
            this.startIP = startip;
            this.endIP = endip;
            this.ipPrefix = ipprefex;
            computerList = new ArrayList();
        }

        public int StartIP
        {
            get { return startIP; }
            set { startIP = value; }
        }

        public int EndIP
        {
            get { return endIP; }
            set { endIP = value; }
        }

        public string IpPrefix
        {
            get { return ipPrefix; }
            set { ipPrefix = value; }
        }

        public ArrayList ComputerList
        {
            get { return computerList; }
            set { computerList = value; }
        }

        public void ScanComputers()
        {
            for (int i = startIP; i <= endIP; i++)
            {
                string scanIP = ipPrefix + "." + i.ToString();
                IPAddress myScanIP = IPAddress.Parse(scanIP);
                IPHostEntry myScanHost = null;
                string[] arr = new string[2];
                try
                {
                    //myScanHost = Dns.GetHostEntry(myScanIP);    
                    myScanHost = Dns.GetHostByAddress(myScanIP);
                }
                catch
                {
                    continue;
                }
                if (myScanHost != null)
                {
                    arr[0] = myScanHost.HostName;
                    arr[1] = scanIP;
                    computerList.Add(arr);
                }
            }
        }
    }
}
